<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.modellist');
class LinkModelLinks extends JModelList{
public function __construct($config = array())
	{
		if (empty($config['filter_fields']))
		{
			$config['filter_fields'] = array(
				'id',
				'title'
			);
		}
		parent::__construct($config);
	}
	
	protected function populateState($ordering = null, $direction = null)
	{
		$app = JFactory::getApplication();

		// Adjust the context to support modal layouts.
		if ($layout = $app->input->get('layout'))
		{
			$this->context .= '.' . $layout;
		}

		$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
		$this->setState('filter.search', $search);
		
		$published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '');
		$this->setState('filter.published', $published);

		// List state information.
		parent::populateState('id', 'desc');
	}
	protected function getListQuery(){
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
	
		$query->select('#__link_rss.*');
		$query->from('#__link_rss');
		$search = $this->getState('filter.search');
		if($search){
			$search = $db->quote('%' . $db->escape($search, true) . '%');
			$query->where('#__link_rss.title LIKE ' . $search );
		}
		$published = $this->getState('filter.published');
		if (is_numeric($published))
		{
			$query->where('#__link_rss.published = ' . (int) $published);
		}
		$query->order('#__link_rss.id desc');
		
		return $query;
	}
}
